import java.io.File;
import java.util.*;

/**
 * Created by isoft-work 5 on 11/22/14.
 */
public class main {
   private static Integer column = 0;
   private static Integer row = 0;
   private static Integer[][] maTrix;

   private static void readMaTrix(String pathToFile) {

      // count number column matrix
      try {
         Scanner sc = new Scanner(new File(pathToFile + "\\src\\main\\resources\\value.txt"));
         sc.useDelimiter("");
         while (sc.hasNext()){
            String s = sc.next();
            if (s.trim().isEmpty()) {
               break;
            }
            column += 1;
         }
         sc.close();
      }
      catch (Exception ex) {
         System.out.print(ex);
      }

      // count number row matrix
      try {
         Scanner sc = new Scanner(new File(pathToFile + "\\src\\main\\resources\\value.txt"));
         sc.useDelimiter("");
         while (sc.hasNext()){
            String s = sc.next();
            if (s.trim().isEmpty()) {
               row += 1;
               continue;
            }
         }
         sc.close();
      }
      catch (Exception ex) {
         System.out.print(ex);
      }

      maTrix = new Integer[row][column];
      row = 0; column = 0;
      // read matrix
      try {
         Scanner sc = new Scanner(new File(pathToFile + "\\src\\main\\resources\\value.txt"));
         sc.useDelimiter("");
         while (sc.hasNextLine()){
            String s = sc.next();
            if (s.trim().isEmpty() && s.equals("\r")) {
               column = 0;
               row += 1;
               continue;
            }
            if(!s.equals("\n")){
               maTrix[row][column++] = Integer.parseInt(s);
            }
         }
         sc.close();
      }
      catch (Exception ex) {
         System.out.print(ex);
      }
   }

   public static void main(String[] args) {
      //      get path of project
      String path = System.getProperty("user.dir");
      readMaTrix(path);
      Rule rule = new Rule(maTrix, column, row + 1, 0.4, 1.0);
      rule.runRule();
   }
}
